/*
Project: 		The Impact of Short-Term Employment for Low-Income Youth: Experimental 	
				Evidence from the Philippines
Authors: 		Emily A. Beam and Stella Quimbo

***********************************
Path: 			code/02_analysis
File name: 		table_07.do 
***********************************

Purpose: 		Generates Tables 7 and associated appendix tables for perceptions/aspirations

Inputs: 		spes_data.dta
Outputs: 		table`tnasp'_iv_`mes'	*Table 7 = table7_ivspes_panel.tex
																															* ITT specifications (appendix)
				table`tnasp'_itt		* Table B4 = table7_itt_panel.tex
								
										* LATE specifications, admin data (appendix)
				table`tnasp'_iv_`mes'	* Table B8 = table7_ivtr_panel.tex


Log: 			results/03_output/log_table_07.log		

Last updated: 	16 November 2021
	*/



cap log close 

log using "$output/log_table_07.log",replace
estimates clear
use "$usedata_analysis/spes_data",clear 
	keep if endline == 1
	
	
*** Set up local variables 

local l_bb_female "Female"
local l_NT_edu "College"

local intlist "_bb_female _NT_edu"

local n: word count $cov1
	assert `n' == 18 

** Interaction terms 

foreach interact in  `intlist' {
	
	foreach mes in tr spes_2016{
gen `mes'X`interact' = `mes'*`interact'
label var `mes'X`interact' "SPES X `l`interact''"

	}

assert !missing(`interact')

gen `interact'xtreatment = `interact'*treatment
label var `interact'xtreatment "SPES X `l`interact''"


* Generate inteaction terms for each covariate 

ds $cov1 
foreach cov in `r(varlist)'{ 
gen `interact'X`cov' = `cov'*`interact'
} 

}




local jtypes "cv online peso fair walkin fam_refer official_refer"



* Set locals 

#delimit ; 
* Work Readiness and Skills ;
local depvar4 " _eeo_tasksi 	_eeo_selfi 		_eeo_lifei 		_eeo_cps_index
				_eeo_job_6mo_ 	_eeo_wage_low 	_eeo_wage_exp 				
				_eeo_exp_hcol 	";
local labels4 " "Work tasks index" "Selfesteem index" "Life skills index" "Workplace skills index" 
				"Likely find job w/in 6 mo. of grad." "Lowest wage willing to accept" 
				"Expected wage after graduation" "Expect to finish college or higher" ";

#delimit cr



										
loc w = 1				

loc name4 "workread"

forval j = 4/4{		
					

local r replace



** Uninteracted version ** 
	foreach var in `depvar`j'' {
	
		areg `var' treatment $cov1 if treatment!=. ,r absorb(scel)
	
			estimates store pa`var'
		summ `var' if treatment==0 
			estadd scalar dmean = `r(mean)'
			
foreach mes in tr spes_2016{

		xi:  ivregress 2sls  `var' (`mes' = treatment ) $cov1  i.scel if treatment!=. ,  robust
		estimates store iv`mes'`var'
		summ `var' if treatment==0 
		estadd scalar dmean = `r(mean)'


}
	
	}
	foreach var in `depvar`j'' {

foreach interact in `intlist'  {


		qui areg `var' treatment `interact'xtreatment $cov1 if treatment != . & _f`interact' == 0  ,r absorb(scel)
	
		estimates store pa`var'`interact'
		summ `var' if treatment==0 
		estadd scalar dmean = `r(mean)'
		test treatment + `interact'xtreatment == 0 
		estadd scalar pvalint = `r(p)'
		
		
		
foreach mes in tr spes_2016{

	
	qui	xi:  ivregress 2sls  `var' (`mes' `mes'X`interact' = treatment `interact'xtreatment) $cov1 `interact'X* i.scel if treatment!=. & _f`interact' == 0,  robust
		
		estimates store iv`mes'`w'`interact'
		di in red "estimates stored as iv`mes'`w'`interact'"
		summ `var' if treatment==0 
		estadd scalar dmean = `r(mean)'
		
		test `mes' + `mes'X`interact' == 0 
		local pval = `r(p)'
		estadd scalar pvalint = `r(p)'
}	// nature of IV loop
		

	
	}		// interaction term
	
	local w = `w' + 1
}		// individual dependent variables within each set
	
}		// dependent variable sets (tables)	

		


********************************************
********************************************


** Table numbers 


loc tnasp = 7 // aspirations

*** Footnote text 


local fn`tnasp' = "\multicolumn{9}{p{1.2\textwidth}}{\footnotesize{Notes: All endline respondents included. All specifications include controls listed in Table \ref{tbal} along with stratification-cell fixed effects.  Work tasks index constructed based on reported experience with 11 office tasks: Microsoft Word, encoding, Excel, Powerpoint, photocopying, scanning, sorting, answering phones, bookkeeping, online searches, and using e-mail. Skill-specific effects reported in Appendix Table \ref{ttasksindiv}. Self-esteem is based on five items drawn from \citet{Rosenberg1965}), life skills is based on a seven-question index developed by the Philippine Bureau of Local Employment, and workplace skills is based on five questions drawn from \citet{Brea2011}. Each index normalized using mean and standard deviation of the control group. \textit{*** p$<$0.01, ** p$<$0.05, * p$<$0.10}. }}\\"

********************************************
********************************************
cd "$tables_analysis"

#delimit ;

********** Table 7 - aspiration panel  *************;
{;
	
	
	// Output Tables ;

	esttab pa_eeo_tasksi 	pa_eeo_selfi 		pa_eeo_lifei 		pa_eeo_cps_index
			pa_eeo_job_6mo_ 	pa_eeo_wage_low 	pa_eeo_wage_exp pa_eeo_exp_hcol   			  
	using table`tnasp'_itt.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	noobs
	keep(treatment) label  
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on labor-market perceptions and aspirations\label{tasp}) 
	varlabels(_cons Constant)  
	mlabels(	"Work tasks index" "Self-esteem index" "Life skills index" "Workplace skills index" 
				"Likely find job w/in 6 mo. of grad." "Lowest wage willing to accept" 
				"Expected wage after graduation" "Expect to finish college or higher" , 
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	collabels(none)
	prehead( "\begin{tabular}{lcccccccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule" );
	
foreach mes in tr spes_2016{;
	
	esttab iv`mes'_eeo_tasksi 	iv`mes'_eeo_selfi 		iv`mes'_eeo_lifei 		iv`mes'_eeo_cps_index
			iv`mes'_eeo_job_6mo_ 	iv`mes'_eeo_wage_low 	iv`mes'_eeo_wage_exp iv`mes'_eeo_exp_hcol   	
	using table`tnasp'_iv_`mes'.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	noobs
	keep(`mes') label  
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on labor-market perceptions and aspirations\label{tasp}) 
	varlabels(_cons Constant) 
	mlabels(	"Work tasks index" "Self-esteem index" "Life skills index" "Workplace skills index" 
				"Likely find job w/in 6 mo. of grad." "Lowest wage willing to accept" 
				"Expected wage after graduation" "Expect to finish college or higher" , 
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	collabels(none)
	prehead( "\begin{tabular}{lcccccccc}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule" );

};



	//* Panel B Female;
	esttab pa_eeo_tasksi_bb_female	pa_eeo_selfi_bb_female 	pa_eeo_lifei_bb_female 	pa_eeo_cps_index_bb_female
			pa_eeo_job_6mo__bb_female pa_eeo_wage_low_bb_female pa_eeo_wage_exp_bb_female pa_eeo_exp_hcol_bb_female
	using table`tnasp'_itt_bb_female.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats( pvalint  , fmt(%9.3f   )  
	labels(  "p-value, SPES + SPES X Female" )) 
	keep(treatment _bb_femalextreatment) label  varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
mlabels(	"Work tasks index" "Self-esteem index" "Life skills index" "Workplace skills index" 
				"Likely find job w/in 6 mo. of grad." "Lowest wage willing to accept" 
				"Expected wage after graduation" "Expect to finish college or higher" , 
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(}))  
	collabels(none)
	prehead(  "\begin{tabular}{lllll}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule"  );
	
foreach mes in tr spes_2016{;

	esttab iv`mes'1_bb_female 		iv`mes'2_bb_female		iv`mes'3_bb_female		iv`mes'4_bb_female  
		 iv`mes'5_bb_female 		iv`mes'6_bb_female		iv`mes'7_bb_female		iv`mes'8_bb_female 
	using table`tnasp'_iv_`mes'_bb_female.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats( pvalint  , fmt(%9.3f   )  
	labels(  "p-value, SPES + SPES X Female" )) 
	keep(`mes' `mes'X_bb_female) label  
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
mlabels(	"Work tasks index" "Self-esteem index" "Life skills index" "Workplace skills index" 
				"Likely find job w/in 6 mo. of grad." "Lowest wage willing to accept" 
				"Expected wage after graduation" "Expect to finish college or higher" , 
			span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	collabels(none)
	prehead("\begin{table}\caption{@title}" "\begin{center}"  "\begin{tabular}{lllll}" "\toprule") 
	posthead(\hline) 
	prefoot() 
	postfoot("\bottomrule"  );
};

	//* Panel C Education ;
	esttab pa_eeo_tasksi_NT_edu	pa_eeo_selfi_NT_edu 	pa_eeo_lifei_NT_edu 	pa_eeo_cps_index_NT_edu
			pa_eeo_job_6mo__NT_edu pa_eeo_wage_low_NT_edu pa_eeo_wage_exp_NT_edu pa_eeo_exp_hcol_NT_edu
	using table`tnasp'_itt_NT_edu.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats(pvalint N dmean , fmt(%9.3f  %9.0f %9.3f )  
	labels( "p-value, SPES + SPES X College" "Observations" "Mean, control group" )) 
	keep(treatment _NT_eduxtreatment) label  
	varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
mlabels(	"Work tasks index" "Self-esteem index" "Life skills index" "Workplace skills index" 
				"Likely find job w/in 6 mo. of grad." "Lowest wage willing to accept" 
				"Expected wage after graduation" "Expect to finish college or higher" , 
				span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(}))  
	collabels(none)
	prehead(  "\begin{tabular}{lllll}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule" "`fn`tnasp''" "\end{tabular}" );
	
foreach mes in tr spes_2016{;

	esttab iv`mes'1_NT_edu		iv`mes'2_NT_edu 			iv`mes'3_NT_edu		iv`mes'4_NT_edu
			iv`mes'5_NT_edu		iv`mes'6_NT_edu 			iv`mes'7_NT_edu		iv`mes'8_NT_edu
	using table`tnasp'_iv_`mes'_NT_edu.tex, replace star(* 0.10 ** 0.05 *** 0.01) 
	cells("b(fmt(3) star)" "se(par([ ]))") 
	stats(pvalint N dmean , fmt(%9.3f  %9.0f %9.3f )  
	labels( "p-value, SPES + SPES X College" "Observations" "Mean, control group" )) 
	keep(`mes' `mes'X_NT_edu) label  varwidth(16) modelwidth(13) style(tex) 
	title(Impact of SPES on employment\label{temployment}) 
	varlabels(_cons Constant) 
mlabels(	"Work tasks index" "Self-esteem index" "Life skills index" "Workplace skills index" 
				"Likely find job w/in 6 mo. of grad." "Lowest wage willing to accept" 
				"Expected wage after graduation" "Expect to finish college or higher" , 
			span prefix(\multicolumn{@span}{x{0.1\textwidth}}{) suffix(})) 
	collabels(none)
	prehead("\begin{table}\caption{@title}" "\begin{center}"  "\begin{tabular}{lllll}" "\toprule") 
	posthead(\hline) prefoot() postfoot("\bottomrule" "`fn`tnasp''" "\end{tabular}" );
};





#delimit ;


// Combine panels ;

include "$dofiles/PanelCombine.do";


panelcombine, use(table`tnasp'_itt.tex table`tnasp'_itt_bb_female.tex table`tnasp'_itt_NT_edu.tex)  
columncount(5) paneltitles("Aggregate treatment effects" "Interacted by gender" "Interacted by education level") cleanup
save(table`tnasp'_itt_panel.tex);



// Table Asp  - IV - Admin ;
panelcombine, use(table`tnasp'_iv_tr.tex table`tnasp'_iv_tr_bb_female.tex table`tnasp'_iv_tr_NT_edu.tex)  
columncount(5) paneltitles("Aggregate treatment effects" "Interacted by gender" "Interacted by education level") cleanup
save(table`tnasp'_ivtr_panel.tex) ;



// Table Asp  - IV - self report ;
panelcombine, use(table`tnasp'_iv_spes_2016.tex table`tnasp'_iv_spes_2016_bb_female.tex table`tnasp'_iv_spes_2016_NT_edu.tex)  
columncount(5)  paneltitles("Aggregate treatment effects" "Interacted by gender" "Interacted by education level") cleanup
save(table`tnasp'_ivspes_panel.tex) ;


};

